<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * CMS
 */
namespace Mall\Controller;
use Common\Controller\AdminController;
use Think\Upload;
/**
 * 菜单
 */
class ClassifyController extends AdminController{
	
	/**
	 *  专辑管理
	 */
    public function All_album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
		}
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	/**
	 *  专辑管理
	 */
    public function tui_album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$map['status'] = 1;
		$map['recommended'] = 1;
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
		}
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	/**
	 *  专辑管理
	 */
    public function no_album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$map['status'] = 3;
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
		}
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
	/* 新增专辑 */
	 public function create_album(){
		 
		 include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		 
		 if(IS_POST){
			$files = getFiles();  
			
			foreach($files as $fileInfo) {  
				$res = uploadFile($fileInfo);  
				if(isset($res['dest'])) {  
					$uploadFiles[] = $res['dest'];  
				}  
			} 
			$str = '';
			$uploadFiles=array_filter($uploadFiles);
			/* dump($files);  
			dump($uploadFiles);die; */
			foreach($uploadFiles as $i=>$v){
				$img_name_list = explode("/",$uploadFiles[$i]);
				$count = count($img_name_list);
				$str_str = substr($uploadFiles[$i],1);
				//dump($str_str);die;
				if($i == 0){
					$str .= $str_str;
				}else{
					$str .= ','.$str_str;
				}
				//dump($img_name_list[$count - 1]);
				upload_file_name($img_name_list[$count - 1],$files[$i]['name'],$uploadFiles[$i],$files[$i]['size']);
			}
			$data['mp3'] = $str;
			 dump($data);die;
			$data['langue'] = I("param.langue");         //语言
			$data['type'] = I("param.type");             //流派风格
			$data['name'] = I("param.name");             //专辑名称
			$data['lyrics'] = I("param.lyrics");          //作词
			$data['compose'] = I("param.compose");        //作曲
			$data['arranged'] = I("param.arranged");      //编曲
			$data['record'] = I("param.record");           //录音
			$data['mixing'] = I("param.mixing");           //混音
			$data['singer'] = I("param.singer");           //演唱者
			$data['producer'] = I("param.producer");       //制作人
			$data['producers'] = I("param.producers");       //出品方
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['color_img'] = I("param.color_img");       //宣传彩页图
			$data['foil_img'] = I("param.foil_img");       //歌词本底衬页图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['type'] = get_mall_model_conf('MALL_ALBUM');
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$data['uid'] = getUID();
			
			$result = $m_mall_content->add($data);
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				$this->success('新增成功', U('Mall/Classify/Album'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
				$this->error('新增失败');
			}
		 }else{
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$type_list = gettypes();
			
			$this->assign("langeue_list",$langeue_list);
			$this->assign("type_list",$type_list);
			$this->assign("time",time());
			$this->display();			
		 }
		 
		
	 }
	
	/* 编辑专辑 */
	 public function Edit_album(){
		$m_mall_content = M('mall_content');
		
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			
			$data['langue'] = I("param.langue");         //语言
			$data['style'] = I("param.style");             //流派风格
			$data['name'] = I("param.name");             //专辑名称
			$data['lyrics'] = I("param.lyrics");          //作词
			$data['compose'] = I("param.compose");        //作曲
			$data['arranged'] = I("param.arranged");      //编曲
			$data['record'] = I("param.record");           //录音
			$data['mixing'] = I("param.mixing");           //混音
			$data['singer'] = I("param.singer");           //演唱者
			$data['producer'] = I("param.producer");       //制作人
			$data['producers'] = I("param.producers");       //出品方
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['color_img'] = I("param.color_img");       //宣传彩页图
			$data['foil_img'] = I("param.foil_img");       //歌词本底衬页图
			$data['intro'] = I("param.intro");       //专辑介绍
			
			$data['ip'] = get_client_ip();
			
			$result = $m_mall_content->where($map)->save($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('编辑成功', U('Mall/Classify/Album'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		
		}else{
			
			$map['type'] = get_mall_model_conf('MALL_ALBUM');
			$map['status'] = array('in','2,4');
			$map['uid'] = getUID();
			$data = $m_mall_content->where($map)->find();
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$type_list = gettypes();
			
			$this->assign("langeue_list",$langeue_list);
			$this->assign("type_list",$type_list);
			$this->assign('data',$data);
			$this->display();
		}
		 
	 }
	
	/* 管理员编辑专辑 */
	 public function Edit_all_album(){
		$m_mall_content = M('mall_content');
		
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			
			$data['langue'] = I("param.langue");         //语言
			$data['style'] = I("param.style");             //流派风格
			$data['name'] = I("param.name");             //专辑名称
			$data['lyrics'] = I("param.lyrics");          //作词
			$data['compose'] = I("param.compose");        //作曲
			$data['arranged'] = I("param.arranged");      //编曲
			$data['record'] = I("param.record");           //录音
			$data['mixing'] = I("param.mixing");           //混音
			$data['singer'] = I("param.singer");           //演唱者
			$data['producer'] = I("param.producer");       //制作人
			$data['producers'] = I("param.producers");       //出品方
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['color_img'] = I("param.color_img");       //宣传彩页图
			$data['foil_img'] = I("param.foil_img");       //歌词本底衬页图
			$data['intro'] = I("param.intro");       //专辑介绍
			
			$data['ip'] = get_client_ip();
			
			$result = $m_mall_content->where($map)->save($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('编辑成功', U('Mall/Classify/All_Album'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		
		}else{
			
			$map['type'] = get_mall_model_conf('MALL_ALBUM');
			$map['status'] = array('in','1,3,2,4');
			$data = $m_mall_content->where($map)->find();
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$type_list = gettypes();
			
			$this->assign("langeue_list",$langeue_list);
			$this->assign("type_list",$type_list);
			$this->assign('data',$data);
			$this->display();
		}
		 
	 }
	
	
	
	/**
	 *  专辑管理
	 */
    public function  Album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$map['uid'] = getUID();
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		
		$status_list = getstatus();
		
		//dump($status_list);die;
		//赋值
		$this->assign('list',$list);
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	/**
	 * 菜单管理
	 */
    public function Manage(){

		common_public()->assign_page('分类管理');
		
		$m_mall_content = M('mall_content');
		
		//获得上级信息
		$fmap['id'] = I('param.form_id')?I('param.form_id'):0;
		$fmap['type'] = get_mall_model_conf('MALL_CLASSIFY');
		$fmap['status'] = 1;
		
		$data = $m_mall_content->where($fmap)->find();
		
		//获得菜单信息
		$map['form_id'] = $fmap['id'];
		$map['type'] = $fmap['type'];
		$map['status'] = 1;
		
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		
		//赋值
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->assign('form_id',$fmap['id']);
		
		
		$this->display();
	}
	
	/**
	 * 新增菜单
	 */
	public function Create(){
		

		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
		
			
			//获得数据
			$data = I();
			
			$data['value'] = I('param.value','','');
			$data['uid'] = getUID();
			$data['form_id'] =  I('param.form_id','','');
			$data['type'] = get_mall_model_conf('MALL_ALBUM');;
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			
			$result = $m_mall_content->add($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
			
			
				
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 编辑菜单
	 */
	public function Edit(){
    
	
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			$map['id'] = I('param.id');
			set_mall_draft($map['id']); //保存草稿
			
			$data = I('');
			unset($data['id']);
		
			$result = $m_mall_content->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 批量删除菜单
	 */
	public function Delete($id,$status=0){
		
	
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_content = M('mall_content');
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				
			
				$id = explode(',',$id); 
				
				
				foreach($id as $i=>$k){
					
					
					$map['id'] = $id[$i];
					$data['status'] = $status;
					
					$m_mall_content->where($map)->save($data);
					
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
			
	
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);


	}
	
	/* 推荐专辑 */
	public function best_album(){
		
		$this->display();
	}
	
	
	/* 专辑评论 */
	public function album_comments(){
		
		$this->display();
	}
	
	/* 活动评论 */
	public function Activity_comments(){
		
		$this->display();
	}
	
	/* 单曲评论 */
	public function Song_comments(){
		
		$this->display();
	}
	
	
}